package com.gxpt.app.fragment;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gxpt.app.AppUtils;
import com.gxpt.app.BaseFragment;
import com.gxpt.app.Constant;
import com.gxpt.app.MessageEvent;
import com.gxpt.app.R;
import com.gxpt.app.view.Activity_center_applylist_shopping_list;
import com.gxpt.app.view.Activity_center_authen;
import com.gxpt.app.view.Activity_center_mycoupon_list;
import com.gxpt.app.view.Activity_center_myneedadd_list;
import com.gxpt.app.view.Activity_center_mytakeneed_list;
import com.gxpt.app.view.Activity_center_orderlist_shopping_list;
import com.gxpt.app.view.Activity_center_storeaddress_list;
import com.gxpt.app.view.Activity_edit_pwd;
import com.gxpt.app.view.Activity_mystore_list;
import com.gxpt.app.view.Activity_service_shop_add_edit;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

/**
 * Created by dufeng on 2017/9/8.
 */

@ContentView(R.layout.fragment_center)
public class Fragment_center extends BaseFragment {

    Context context;


    @ViewInject(R.id.type1)
    ImageView type1;

    @ViewInject(R.id.type2)
    ImageView type2;

    @ViewInject(R.id.type3)
    ImageView type3;

    @ViewInject(R.id.type4)
    ImageView type4;

    @ViewInject(R.id.txt1)
    TextView txt1;

    @ViewInject(R.id.txt2)
    TextView txt2;

    @ViewInject(R.id.txt3)
    TextView txt3;

    @ViewInject(R.id.txt4)
    TextView txt4;

    @ViewInject(R.id.userID)
    TextView userID;

    @ViewInject(R.id.user_count)
    TextView user_count;



    @ViewInject(R.id.toOrder_list_shopping)
    LinearLayout toOrder_list_shopping;

    @ViewInject(R.id.to_life_need_add)
    RelativeLayout to_life_need_add;

    @ViewInject(R.id.toMytakeNeed)
    RelativeLayout toMytakeNeed;


    @ViewInject(R.id.to_address_list)
    RelativeLayout to_address_list;

    @ViewInject(R.id.to_coupon_list)
    RelativeLayout to_coupon_list;



    @ViewInject(R.id.toMyStoreList_need)
    RelativeLayout toMyStoreList_need;

    @ViewInject(R.id.toAuthen)
    RelativeLayout toAuthen;

    @ViewInject(R.id.toEditServiceInfo)//服务商编辑资料
    RelativeLayout toEditServiceInfo;

    @ViewInject(R.id.toEditPWD)//修改密码
    RelativeLayout toEditPWD;

    @ViewInject(R.id.toApply_shopping)//售后
    RelativeLayout toApply_shopping;



    @ViewInject(R.id.toLogin)//修改密码
    Button toLogin;


    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if(hidden == false){
            AppUtils.isShowAreaSel(context);
        }
    }

    @Override
    public void onAttach(Context context) {
        this.context = context;
        super.onAttach(context);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
    }

    @Override
    public void onDestroyView() {
        EventBus.getDefault().unregister(this);
        super.onDestroyView();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMoonEvent(MessageEvent messageEvent){
        if(messageEvent.getMessageType() == Constant.ACTION_refresh_center){
            userID.setText(""+AppUtils.get_XML_tel(context));
            user_count.setText("用户等级:"+AppUtils.get_mem_level(context));
        }
    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = x.view().inject(this, inflater, container);
        initViews();
        initData();
        return rootView;
    }

    private void initData() {
        userID.setText(""+AppUtils.get_XML_tel(context));
        user_count.setText("用户等级:"+AppUtils.get_mem_level(context));
    }




    private void initViews() {
    }

    @Event(value={R.id.to_life_need_add,R.id.to_address_list,R.id.toMyStoreList_need,R.id.toAuthen,
            R.id.toEditPWD,R.id.toEditServiceInfo,R.id.toLogin,R.id.toMytakeNeed,R.id.to_coupon_list,
            R.id.toOrder_list_shopping,R.id.type1,R.id.type2,R.id.type3,R.id.type4,R.id.txt1,R.id.txt2,R.id.txt3,R.id.txt4,
            R.id.toApply_shopping})
    private void getEvent(View view){
        Bundle b = new Bundle();
        Intent goViews = new Intent();
        switch(view.getId()){
            case R.id.type1:
            case R.id.txt1:
                b.putInt("TYPE",1);
                goViews.putExtra("DATA",b);
                goViews.setClass(context, Activity_center_orderlist_shopping_list.class);
                startActivity(goViews);
                break;
            case R.id.type2:
            case R.id.txt2:
                b.putInt("TYPE",2);
                goViews.putExtra("DATA",b);
                goViews.setClass(context, Activity_center_orderlist_shopping_list.class);
                startActivity(goViews);
                break;
            case R.id.type3:
            case R.id.txt3:
                b.putInt("TYPE",3);
                goViews.putExtra("DATA",b);
                goViews.setClass(context, Activity_center_orderlist_shopping_list.class);
                startActivity(goViews);
                break;
            case R.id.type4:
            case R.id.txt4:
                b.putInt("TYPE",4);
                goViews.putExtra("DATA",b);
                goViews.setClass(context, Activity_center_orderlist_shopping_list.class);
                startActivity(goViews);
                break;
            case R.id.toOrder_list_shopping:
                goViews.setClass(context, Activity_center_orderlist_shopping_list.class);
                startActivity(goViews);
                break;
            case R.id.to_life_need_add:
                goViews.setClass(context, Activity_center_myneedadd_list.class);
                startActivity(goViews);
                break;
            case R.id.toMytakeNeed:
                goViews.setClass(context, Activity_center_mytakeneed_list.class);//我承接的需求
                startActivity(goViews);
                break;
            case R.id.to_address_list:
                goViews.setClass(context, Activity_center_storeaddress_list.class);
                startActivity(goViews);
                break;
            case R.id.to_coupon_list:
                goViews.setClass(context, Activity_center_mycoupon_list.class);
                startActivity(goViews);
                break;
            case R.id.toMyStoreList_need:
                goViews.setClass(context, Activity_mystore_list.class);
                startActivity(goViews);
                break;
            case R.id.toAuthen:
                goViews.setClass(context, Activity_center_authen.class);
                startActivity(goViews);
                break;
            case R.id.toEditPWD:
                goViews.setClass(context, Activity_edit_pwd.class);
                startActivity(goViews);
                break;
            case R.id.toEditServiceInfo:
                goViews.setClass(context, Activity_service_shop_add_edit.class);
                startActivity(goViews);
                break;
            case R.id.toApply_shopping:
                goViews.setClass(context, Activity_center_applylist_shopping_list.class);
                startActivity(goViews);
                break;
            case R.id.toLogin:
                AppUtils.putXML_user_exit(context);
                EventBus.getDefault().post(new MessageEvent(
                        Constant.ACTION_FRAGMENT_TO_HOME));
                break;
        }
    }
}
